/**
 * Main.js Class
 * 2012. 4. 11.
 * Kim Chan Soo
 */
function Main()
{
	_main = this;
}
Main.prototype.onLoad = function()
{
	_main.onStart();
};
Main.prototype.onStart = function()
{
	this.canvas = Dom.createCanvas("canvas", 0, 0, window.innerWidth, window.innerHeight);
	Dom.appendBody(this.canvas);
	
	this.canvas.addEventListener("mousemove", function(event){ _main.onMouseMove(event); }, false);
	this.context = this.canvas.getContext("2d");
	this.mouseX = 0;
	this.mouseY = 0;
	
	this.arrWon = [];
	this.index = 0;
	
	setInterval(function(){ _main.onRun(); }, 1000/60);
};
Main.prototype.onRun = function()
{
	console.log("test");
	this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
	//console.log(this.arrWon.length);
	for(var i = 0 ; i < this.arrWon.length ; i++)
	{
		this.context.beginPath();
		this.context.fillStyle = this.arrWon[i].color;
		this.arrWon[i].x += this.arrWon[i].speedx;
		this.arrWon[i].y += this.arrWon[i].speedy;
		console.log(this.arrWon[i].color);
		//this.context.fillRect(this.arrWon[i].x, this.arrWon[i].y, this.arrWon[i].width, this.arrWon[i].height);
		//this.context.arc(this.arrWon[i].x, this.arrWon[i].y, this.arrWon[i].width, 0, 2 * Math.PI, false);//360 = 2 * Math.PI
		this.context.arc(this.arrWon[i].x, this.arrWon[i].y, this.arrWon[i].width, 0, (Math.PI/180)*360, false);//360 = 2 * Math.PI
		
		//this.context.arc(x, y, radius, startAngle, endAngle, anticlockwise);
		//this.context.arc(100, 100, 50, (Math.PI/180)*0, (Math.PI/180)*360, false);
		this.context.closePath();
		this.context.fill();
		//this.context.arc(100, 100, 50, (Math.PI/180)*0, (Math.PI/180)*180, false);
		//this.context.closePath();
	}
	
	
};
Main.prototype.onMouseMove = function(e)
{
	//console.log(e.clientX + ", " + e.clientY);
	this.mouseX = e.clientX;
	this.mouseY = e.clientY;
	var one = new One(this.mouseX, this.mouseY, Math.random()* 300 + 50, Math.random() * 300 + 50, this.getRandomColor());
	this.arrWon[this.index] = one;
	this.index = (this.index + 1) % 1000;
};
/**
 * 랜덤 RGB 컬러 반환
 * @returns {String}
 */
Main.prototype.getRandomColor = function()
{
	var r = Math.round(Math.random() * 255);
	var g = Math.round(Math.random() * 255);
	var b = Math.round(Math.random() * 255);
	return "rgb(" + r + "," + g + "," + b + ")";
};
function One(x, y, width, height, color)
{
	this.x = x;
	this.y = y;
	this.width = width;
	this.height = height;
	this.color = color;
	this.speedx = Math.sin(x);
	this.speedy = Math.cos(y);
}
var main = new Main();
window.onload = main.onLoad;